<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    protected string $tableName = 'admin_roles';

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable($this->tableName)) {
            return;
        }
        Schema::create($this->tableName, function (Blueprint $table) {
            $table->comment('后台角色表');
            $table->increments('id')->comment('主键ID');
            $table->integer('created_id')->default(0)->comment('');
            $table->integer('created_at')->default(0)->comment('');
            $table->integer('updated_id')->default(0)->comment('');
            $table->integer('updated_at')->default(0)->comment('');
            $table->integer('deleted_id')->default(0)->nullable()->comment('');
            $table->integer('deleted_at')->default(0)->nullable()->comment('');
            $table->integer('parent_id')->default(0)->comment('上级ID');
            $table->string('name', 20)->default('')->comment('名称');
            $table->tinyInteger('role_type')->default(1)->nullable()->comment('类型 1-总后台 2-其他');
            $table->text('access')->nullable()->comment('用户组拥有的规则ID，多个规则用 , 隔开（rules）');
            $table->string('remark', 255)->default('')->nullable()->comment('');
            $table->integer('sorting')->default(0)->nullable()->comment('');
            $table->tinyInteger('status')->default(0)->comment('状态 1-正常 2-禁用');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists($this->tableName);
    }
};
